package com.vm.db;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * 数据库帮助类
 * 
 * @author WikerYong Email:<a href="#">yw_312@foxmail.com</a>
 * @version 2012-3-31 上午11:16:03
 */
public class DBOpenHelper extends SQLiteOpenHelper {

	private static final String TAG = "DBOpenHelper";

	public static SQLiteDatabase db = null;

	public DBOpenHelper(Context context) {
		super(context, "download.db", null, 4);
		db = getWritableDatabase();
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		try {
			db.execSQL("CREATE TABLE downInfo (path VARCHAR(1024), softId VARCHAR(50),name varchar(50),imageUrl varchar(200),isPause INTEGER, done INTEGER,apkLength INTEGER,completed Integer, PRIMARY KEY(path, softId))");
			db.execSQL("CREATE TABLE LocalUserInfo(userId varchar(40),username varchar(40),intergral INTEGER,imageUrl varchar(200),PRIMARY KEY(userId))");
		} catch (SQLException e) {
			Log.e(TAG, e.getMessage());
		} finally {
			if (db.isOpen() && db != null) {
				// db.close();
			}
		}

		try {
			db.execSQL("CREATE TABLE upgradeSoft (id VARCHAR(40), softId VARCHAR(50),name varchar(50),packageName varchar(100),currentVersion varchar(20),newVersion varchar(20), size float, PRIMARY KEY(id))");
		} catch (SQLException e) {
			Log.e(TAG, e.getMessage());
		} finally {
			if (db.isOpen() && db != null) {
				// db.close();
			}
		}

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		onCreate(db);
	}

}